package com.yonyougov.devops.cruxcisupport.harborhis;

import com.yonyougov.devops.cruxcisupport.harborhis.dto.HarborHisQueryRequestDto;
import com.yonyougov.devops.fwc.api.dto.BaseResponseDto;
import com.yonyougov.devops.fwc.core.controller.CrudController;
import com.yonyougov.devops.fwc.core.entity.Pagination;
import com.yonyougov.devops.fwc.core.service.BaseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigInteger;

/**
* Created by ligson on 2017/8/11.
*/
@RestController
@RequestMapping("/api/v2/harborhis")
public class HarborHisController extends CrudController<HarborHisEntity, BigInteger> {

    @Autowired
    private HarborHisService harborHisService;

    @Override
    public BaseService<HarborHisEntity, BigInteger> getService() {
        return harborHisService;
    }

    //<!--用户自定义代码开始-->
    @ApiOperation(value = "查询harbor镜像操作历史", notes = "查询harbor镜像操作历史")
    @PostMapping(value = "/hh/query")
    public BaseResponseDto findCommitTestPageLike(@RequestBody @Valid HarborHisQueryRequestDto requestDto) {
        HarborHisEntity build = HarborHisEntity.builder().projectName(requestDto.getProjectName()).repositoryName(requestDto.getAppName()).imageVersion(requestDto.getVersionName()).build();
        BeanUtils.copyProperties(requestDto,build);
        Pagination<HarborHisEntity> pagination = harborHisService.likeAllBy(build);

        BaseResponseDto result = BaseResponseDto.getSuccessInstance();
        result.put("totalCount", pagination.getTotalCount());
        result.put("data", pagination.getDatas());
        return result;
    }
    //<!--用户自定义代码结束-->
}
